﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

public class ApplicationEnvironment
{
    private static ApplicationEnvironment _instance;

    public static ApplicationEnvironment Instance
    {
        get
        {
            lock (typeof(ApplicationEnvironment))
            {
                if (HttpContext.Current.Session["ApplicationEnvironment_Instance"] == null)
                    HttpContext.Current.Session["ApplicationEnvironment_Instance"] = new ApplicationEnvironment();

                return HttpContext.Current.Session["ApplicationEnvironment_Instance"] as ApplicationEnvironment;
            }
        }
    }
    //classe com ums instancia da classe, garante com 

    public ServiceGerenciador.Model.User User
    {
        get
        {
            return ServiceGerenciador.Model.User.FindAllByProperty("Id", Convert.ToInt32(HttpContext.Current.User.Identity.Name)).FirstOrDefault();
        }
    }

    public IDictionary<string, string> Flash
    {
        get 
        {
            if(HttpContext.Current.Session["ApplicationEnvironment_Flash"] == null)
               HttpContext.Current.Session["ApplicationEnvironment_Flash"] = new Dictionary<string,string>();

            return HttpContext.Current.Session["ApplicationEnvironment_Flash"] as Dictionary<string, string>;
        }
        set
        {
            HttpContext.Current.Session["ApplicationEnvironment_Flash"] = value;
        }
    }
}